﻿<UserControl x:Class="Berico.SnagL.Infrastructure.Controls.SearchTool"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:local="clr-namespace:Berico.SnagL.Infrastructure.Controls"   
    xmlns:common="clr-namespace:Berico.Common.UI.Triggers;assembly=Berico.Common"
    xmlns:berico="clr-namespace:Berico.Windows.Controls;assembly=Berico.Windows.Controls"  
    xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.SL4"             
    xmlns:MS="clr-namespace:Microsoft.Windows.Controls;assembly=Microsoft.Windows.Controls.WatermarkedTextBox"
    xmlns:convertors="clr-namespace:Berico.Common.UI.Converters;assembly=Berico.Common"             
    xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"
    xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"       
    xmlns:triggers="clr-namespace:Berico.Common.UI.Triggers;assembly=Berico.Common"
    mc:Ignorable="d"
    d:DesignHeight="25" d:DesignWidth="400"
    DataContext="{Binding SearchToolVM, Source={StaticResource Locator}}">

    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Loaded">
            <common:AdvancedEventToCommand Command="{Binding SearchToolLoadedCommand}" PassEventDetailsToCommand="True" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
    
    <UserControl.Resources>
        <convertors:VisibilityConverter x:Key="VisibilityConverter" />
        
        <Path x:Name="SearchIcon" StrokeThickness="3.000000" Stroke="#FF5C5C5C" StrokeMiterLimit="1.000000" Data="F1 M 11.834961,12.237793 L 17.326172,18.979980 M 14.341309,8.301270 C 13.845215,11.566406 10.583008,13.840820 7.054199,13.381836 C 3.525879,12.922852 1.067383,9.904785 1.563477,6.639648 C 2.059082,3.375000 5.321289,1.100098 8.850098,1.559082 C 12.378906,2.018066 14.837402,5.036621 14.341309,8.301270 Z"/>
        <Path x:Name="FilterIcon" Margin="4" Fill="#FF5C5C5C" Data="F1 M21.000002,0 L0,0 L8.7654037,11.982794 L8.7498274,11.983832 L8.7498274,21.000002 L12.298458,21.000002 L12.298458,11.895571 L21.000002,0 z" VerticalAlignment="Center" HorizontalAlignment="Center" Stretch="Uniform"/>

        <ControlTemplate x:Key="MenuItemTemplate" TargetType="ListBoxItem">
            <Grid Background="{TemplateBinding Background}">
                <VisualStateManager.VisualStateGroups>
                    <VisualStateGroup x:Name="CommonStates">
                        <VisualState x:Name="Normal"/>
                        <VisualState x:Name="MouseOver">
                            <Storyboard>
                                <DoubleAnimation Duration="0" To=".35" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="fillColor"/>
                            </Storyboard>
                        </VisualState>
                        <VisualState x:Name="Disabled">
                            <Storyboard>
                                <DoubleAnimation Duration="0" To=".55" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="contentPresenter"/>
                            </Storyboard>
                        </VisualState>
                    </VisualStateGroup>
                    <VisualStateGroup x:Name="SelectionStates">
                        <VisualState x:Name="Unselected"/>
                        <VisualState x:Name="Selected">
                            <Storyboard>
                                <DoubleAnimation Duration="0" To=".75" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="fillColor2"/>
                            </Storyboard>
                        </VisualState>
                    </VisualStateGroup>
                    <VisualStateGroup x:Name="FocusStates">
                        <VisualState x:Name="Focused">
                            <Storyboard>
                                <ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Visibility" Storyboard.TargetName="FocusVisualElement">
                                    <DiscreteObjectKeyFrame KeyTime="0">
                                        <DiscreteObjectKeyFrame.Value>
                                            <Visibility>Visible</Visibility>
                                        </DiscreteObjectKeyFrame.Value>
                                    </DiscreteObjectKeyFrame>
                                </ObjectAnimationUsingKeyFrames>
                            </Storyboard>
                        </VisualState>
                        <VisualState x:Name="Unfocused"/>
                    </VisualStateGroup>
                </VisualStateManager.VisualStateGroups>
                <Rectangle x:Name="fillColor" Fill="#FFBADDE9" IsHitTestVisible="False" Opacity="0" RadiusY="1" RadiusX="1"/>
                <Rectangle x:Name="fillColor2" Fill="#FFBADDE9" IsHitTestVisible="False" Opacity="0" RadiusY="1" RadiusX="1"/>
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" MinWidth="24" />
                        <ColumnDefinition Width="4" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="17" />
                    </Grid.ColumnDefinitions>
                    <ContentPresenter Content="{Binding Icon}" Margin="1" VerticalAlignment="Center" />
                    <ContentPresenter x:Name="contentPresenter" Grid.Column="2" Margin="{TemplateBinding Padding}" Content="{Binding Header}" />
                </Grid>
                <Rectangle x:Name="FocusVisualElement" Grid.Column="0" Grid.ColumnSpan="2" RadiusY="1" RadiusX="1" Stroke="#FF6DBDD1" StrokeThickness="1" Visibility="Collapsed"/>
            </Grid>
        </ControlTemplate>

        <ControlTemplate x:Key="MenuList" TargetType="ListBox">
            <Grid>
                <Border>
                    <ItemsPresenter />
                </Border>
            </Grid>
        </ControlTemplate>

        <Style TargetType="ListBoxItem" x:Key="MenuItemStyle">
            <Setter Property="Padding" Value="4,3,2,3" />
            <Setter Property="Template" Value="{StaticResource MenuItemTemplate}" />
        </Style>

        <Style x:Key="MenuListStyle" TargetType="ListBox">
            <Setter Property="Template" Value="{StaticResource MenuList}" />
            <Setter Property="ItemContainerStyle" Value="{StaticResource MenuItemStyle}" />
        </Style>
        
        <Style x:Key="SearchButtonStyle" TargetType="berico:SplitButton">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="berico:SplitButton">
                        <Grid x:Name="LayoutRoot">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <Grid.Resources>
                                <Style x:Key="BlankButton" TargetType="Button">
                                    <Setter Property="IsEnabled" Value="true"/>
                                    <Setter Property="IsTabStop" Value="true"/>
                                    <Setter Property="Background" Value="Transparent"/>
                                    <Setter Property="Foreground" Value="#FF000000"/>
                                    <Setter Property="MinWidth" Value="5"/>
                                    <Setter Property="MinHeight" Value="5"/>
                                    <Setter Property="HorizontalAlignment" Value="Left" />
                                    <Setter Property="HorizontalContentAlignment" Value="Left"/>
                                    <Setter Property="VerticalContentAlignment" Value="Center"/>
                                    <Setter Property="Cursor" Value="Hand"/>
                                    <!--<Setter Property="TextAlignment" Value="Left"/>-->
                                    <!--<Setter Property="TextWrapping" Value="NoWrap"/>-->
                                    <!--<Setter Property="FontWeight" Value="Bold" />-->
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate TargetType="Button">
                                                <Grid Height="Auto" Width="Auto">
                                                    <Grid.Resources>
                                                        <LinearGradientBrush x:Key="ButtonBorderGradient" EndPoint="0.5,1" StartPoint="0.5,0">
                                                            <GradientStop Color="#FF4F4F4F"/>
                                                            <GradientStop Color="#FF464646" Offset="1"/>
                                                        </LinearGradientBrush>
                                                        <SolidColorBrush x:Key="DisabledBrush" Color="#A5FFFFFF"/>
                                                    </Grid.Resources>
                                                    <vsm:VisualStateManager.VisualStateGroups>
                                                        <vsm:VisualStateGroup x:Name="CommonStates">
                                                            <vsm:VisualStateGroup.Transitions>
                                                                <vsm:VisualTransition GeneratedDuration="0:0:0.2" To="Pressed"/>
                                                            </vsm:VisualStateGroup.Transitions>
                                                            <vsm:VisualState x:Name="Normal" />
                                                            <vsm:VisualState x:Name="Pressed" />
                                                            <vsm:VisualState x:Name="Disabled">
                                                                <!--<Storyboard>
                                                                    <DoubleAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="DisabledVisual" Storyboard.TargetProperty="Opacity">
                                                                        <SplineDoubleKeyFrame KeyTime="0" Value="1"/>
                                                                    </DoubleAnimationUsingKeyFrames>
                                                                </Storyboard>-->
                                                            </vsm:VisualState>
                                                        </vsm:VisualStateGroup>
                                                    </vsm:VisualStateManager.VisualStateGroups>
                                                    <ContentPresenter x:Name="Content" Margin="{TemplateBinding Padding}" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                                                    <Border x:Name="DisabledVisual" Background="{StaticResource DisabledBrush}" BorderBrush="Transparent" BorderThickness="1" CornerRadius="5,0,0,5" Opacity="0" HorizontalAlignment="Stretch" />
                                                </Grid>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </Grid.Resources>
                            <vsm:VisualStateManager.VisualStateGroups>
                                <vsm:VisualStateGroup x:Name="CommonStates">
                                    <vsm:VisualStateGroup.Transitions>
                                        <vsm:VisualTransition GeneratedDuration="0:0:0.2" To="Pressed"/>
                                    </vsm:VisualStateGroup.Transitions>
                                    <vsm:VisualState x:Name="Normal" />
                                    <vsm:VisualState x:Name="Pressed" />
                                    <vsm:VisualState x:Name="Disabled">
                                        <Storyboard>
                                            <!--<DoubleAnimationUsingKeyFrames Duration="0" Storyboard.TargetName="DisabledVisual" Storyboard.TargetProperty="Opacity">
                                                <SplineDoubleKeyFrame KeyTime="0" Value="1"/>
                                            </DoubleAnimationUsingKeyFrames>-->
                                        </Storyboard>
                                    </vsm:VisualState>
                                </vsm:VisualStateGroup>
                            </vsm:VisualStateManager.VisualStateGroups>
                            <Popup x:Name="DropDownPopup" HorizontalOffset="0" VerticalOffset="0">
                                <Grid Height="Auto" HorizontalAlignment="Left" VerticalAlignment="Top" Opacity="1">
                                    <Border x:Name="DropDownPopupBorder" Background="#F0F0F0" BorderBrush="#A0A0A0" BorderThickness="1,1,1,1" Margin="0,0,0,0" Height="Auto" Width="Auto">
                                        <ContentPresenter x:Name="DropDownPopupContent" Content="{TemplateBinding DropDownContent}" />
                                    </Border>
                                </Grid>
                            </Popup>
                            <Border x:Name="Background" Grid.Column="0" Grid.ColumnSpan="2" CornerRadius="15,0,0,15" Background="#FFA9A9A9" />
                            <Border x:Name="BackgroundGradient" Grid.Column="0" Grid.ColumnSpan="2" CornerRadius="15,0,0,15">
                                <Border.Background>
                                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                        <GradientStop Color="#FCFFFFFF"/>
                                        <GradientStop Color="#4CFFFFFF" Offset="1"/>
                                    </LinearGradientBrush>
                                </Border.Background>
                            </Border>
                            <Button x:Name="ActionButton" Margin="2" Padding="5,0,2,0" Grid.Column="0" Style="{StaticResource BlankButton}" Content="{TemplateBinding Content}" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" MinWidth="30" Width="Auto" />
                            <Button x:Name="PopupButton" Grid.Column="1" Padding="0" Width="12" Style="{StaticResource BlankButton}" VerticalContentAlignment="Center">
                                <Button.Content>
                                    <Path Margin="2,0,2,0" Stretch="Uniform" StrokeThickness="1" StrokeEndLineCap="Triangle" StrokeLineJoin="Round" Stroke="#FF5C5C5C" VerticalAlignment="Bottom" StrokeMiterLimit="1.000000" Fill="#FF5C5C5C" Data="F1 M 20.744629,15.662109 L 17.576172,10.995117 L 24.201172,10.995117 L 20.744629,15.662109 Z"/>
                                </Button.Content>
                            </Button>
                            <Border Grid.Column="1" BorderThickness="1,0,1,0" Width="12" Margin="0,-1,0,-.5">
                                <Border.BorderBrush>
                                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                        <GradientStop Color="#FF4F4F4F"/>
                                        <GradientStop Color="#FF464646" Offset="1"/>
                                    </LinearGradientBrush>
                                </Border.BorderBrush>
                            </Border>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style x:Key="PlainRoundButtonStyle" TargetType="Button">
            <Setter Property="IsEnabled" Value="true"/>
            <Setter Property="IsTabStop" Value="true"/>
            <Setter Property="Background" Value="#FFA9A9A9"/>
            <Setter Property="Foreground" Value="#FF000000"/>
            <Setter Property="MinWidth" Value="5"/>
            <Setter Property="MinHeight" Value="5"/>
            <Setter Property="Margin" Value="0"/>
            <Setter Property="Cursor" Value="Arrow"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Grid Height="Auto" Width="Auto">
                            <Grid.Resources>
                                <LinearGradientBrush x:Key="ButtonBorderGradient" EndPoint="0.5,1" StartPoint="0.5,0">
                                    <GradientStop Color="#FF4F4F4F"/>
                                    <GradientStop Color="#FF464646" Offset="1"/>
                                </LinearGradientBrush>
                                <SolidColorBrush x:Key="DisabledBrush" Color="#A5FFFFFF"/>
                            </Grid.Resources>
                            <vsm:VisualStateManager.VisualStateGroups>
                                <vsm:VisualStateGroup x:Name="CommonStates">
                                    <vsm:VisualStateGroup.Transitions>
                                        <vsm:VisualTransition GeneratedDuration="0:0:0.2" To="Pressed"/>
                                    </vsm:VisualStateGroup.Transitions>
                                    <vsm:VisualState x:Name="Normal" />
                                    <vsm:VisualState x:Name="Pressed">
                                        <Storyboard>
                                            <DoubleAnimation Duration="0" Storyboard.TargetName="ButtonBackground" Storyboard.TargetProperty="Opacity" To="1"/>
                                        </Storyboard>
                                    </vsm:VisualState>
                                    <vsm:VisualState x:Name="Disabled">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="DisabledOverlay" Storyboard.TargetProperty="Visibility" Duration="0">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <Visibility>Visible</Visibility>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </vsm:VisualState>
                                </vsm:VisualStateGroup>
                            </vsm:VisualStateManager.VisualStateGroups>
                            <Ellipse x:Name="ButtonBackground" Fill="#FF8E8E8E" Opacity=".50"/>
                            <ContentPresenter x:Name="Content" Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                            <Ellipse x:Name="DisabledOverlay" Fill="White" Opacity=".55" Visibility="Collapsed" IsHitTestVisible="False" />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style x:Key="CollapseButtonStyle" TargetType="ToggleButton">
            <Setter Property="IsChecked" Value="False"/>
            <Setter Property="Cursor" Value="Hand"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ToggleButton">
                        <Grid x:Name="Root">
                            <vsm:VisualStateManager.VisualStateGroups>
                                <vsm:VisualStateGroup x:Name="CommonStates">
                                    <vsm:VisualStateGroup.Transitions>
                                        <vsm:VisualTransition GeneratedDuration="0:0:0.1" To="MouseOver"/>
                                        <vsm:VisualTransition GeneratedDuration="0:0:0" To="Pressed"/>
                                    </vsm:VisualStateGroup.Transitions>
                                    <vsm:VisualState x:Name="Normal" />
                                    <vsm:VisualState x:Name="MouseOver" />
                                </vsm:VisualStateGroup>
                                <vsm:VisualStateGroup x:Name="CheckStates">
                                    <vsm:VisualStateGroup.Transitions>
                                        <vsm:VisualTransition GeneratedDuration="0:0:0"/>
                                    </vsm:VisualStateGroup.Transitions>
                                    <!-- Checked = Expanded -->
                                    <vsm:VisualState x:Name="Checked">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonBackground" Storyboard.TargetProperty="Visibility" Duration="0">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <Visibility>Visible</Visibility>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                            <DoubleAnimation Storyboard.TargetName="IconRotateTransform" Storyboard.TargetProperty="Angle" To="180" Duration="00:00:0.2" />
                                        </Storyboard>
                                    </vsm:VisualState>
                                    <!-- Unchecked = Collapsed -->
                                    <vsm:VisualState x:Name="Unchecked">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonBackground" Storyboard.TargetProperty="Visibility" Duration="0">
                                                <DiscreteObjectKeyFrame KeyTime="0">
                                                    <DiscreteObjectKeyFrame.Value>
                                                        <Visibility>Collapsed</Visibility>
                                                    </DiscreteObjectKeyFrame.Value>
                                                </DiscreteObjectKeyFrame>
                                            </ObjectAnimationUsingKeyFrames>
                                            <DoubleAnimation Storyboard.TargetName="IconRotateTransform" Storyboard.TargetProperty="Angle" To="0" Duration="00:00:0.2" />
                                        </Storyboard>
                                    </vsm:VisualState>
                                </vsm:VisualStateGroup>
                            </vsm:VisualStateManager.VisualStateGroups>
                            <Grid>
                                <Border x:Name="ButtonBackground" CornerRadius="6,6,0,0" BorderThickness="2,2,2,0" Margin="-1,0,0,0" Visibility="Collapsed" Background="#FFB9BABF">
                                    <Border.BorderBrush>
                                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                            <GradientStop Color="#FF4F4F4F"/>
                                            <GradientStop Color="#FF464646" Offset="1"/>
                                        </LinearGradientBrush>
                                    </Border.BorderBrush>
                                </Border>
                                <Border Background="Transparent">
                                    <Path x:Name="Icon" Grid.Row="0" Grid.RowSpan="2" Margin="3,4,4,1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Data="M1.5,1.904605 L22.173403,21.865133 M42.500004,1.5 L22.539474,22.173403 M1.5,31.904606 L22.173403,51.865131 M42.500004,31.5 L22.539474,52.173401" Fill="#FFFFFFFF" Stretch="Fill" Stroke="#FFFBFAFA" StrokeEndLineCap="Round"  StrokeLineJoin="Round" StrokeStartLineCap="Round" StrokeThickness="2.5" RenderTransformOrigin="0.5,0.5">
                                        <Path.RenderTransform>
                                            <TransformGroup>
                                                <ScaleTransform/>
                                                <SkewTransform/>
                                                <RotateTransform x:Name="IconRotateTransform" Angle="0"/>
                                                <TranslateTransform/>
                                            </TransformGroup>
                                        </Path.RenderTransform>
                                    </Path>
                                </Border>
                            </Grid>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="LowKeyWatermarkedTextboxStyle" TargetType="MS:WatermarkedTextBox">
            <Setter Property="BorderThickness" Value="0" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="MS:WatermarkedTextBox">
                        <Grid x:Name="LayoutRoot">
                            <Grid.Resources>
                                <SolidColorBrush x:Key="WatermarkBrush" Color="#FFAAAAAA"/>
                            </Grid.Resources>
                            <vsm:VisualStateManager.VisualStateGroups>
                                <vsm:VisualStateGroup x:Name="CommonStates">
                                    <vsm:VisualStateGroup.Transitions>
                                        <vsm:VisualTransition GeneratedDuration="0" />
                                    </vsm:VisualStateGroup.Transitions>
                                    <vsm:VisualState x:Name="Normal" />
                                    <vsm:VisualState x:Name="MouseOver">
                                        <Storyboard>
                                            <ColorAnimation Storyboard.TargetName="MouseOverBorder" Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)" To="#FF99C1E2" Duration="0"/>
                                        </Storyboard>
                                    </vsm:VisualState>
                                    <vsm:VisualState x:Name="Disabled">
                                        <Storyboard>
                                            <DoubleAnimation Storyboard.TargetName="DisabledVisualElement" Storyboard.TargetProperty="Opacity" To="0.5" Duration="0" />
                                        </Storyboard>
                                    </vsm:VisualState>
                                </vsm:VisualStateGroup>
                                <vsm:VisualStateGroup x:Name="WatermarkStates">
                                    <vsm:VisualStateGroup.Transitions>
                                        <vsm:VisualTransition GeneratedDuration="0" />
                                    </vsm:VisualStateGroup.Transitions>
                                    <vsm:VisualState x:Name="Unwatermarked" />
                                    <vsm:VisualState x:Name="Watermarked">
                                        <Storyboard>
                                            <DoubleAnimation Storyboard.TargetName="ContentElement" Storyboard.TargetProperty="Opacity" To="0" Duration="0" />
                                            <DoubleAnimation Storyboard.TargetName="Watermark" Storyboard.TargetProperty="Opacity" To="1" Duration="0" />
                                        </Storyboard>
                                    </vsm:VisualState>
                                </vsm:VisualStateGroup>
                                <vsm:VisualStateGroup x:Name="FocusStates">
                                    <vsm:VisualStateGroup.Transitions>
                                        <vsm:VisualTransition GeneratedDuration="0" />
                                        <vsm:VisualTransition To="Focused" GeneratedDuration="0:0:0.1" />
                                    </vsm:VisualStateGroup.Transitions>
                                    <vsm:VisualState x:Name="Unfocused" />
                                    <vsm:VisualState x:Name="Focused">
                                        <Storyboard>
                                            <!--<DoubleAnimation Storyboard.TargetName="FocusVisual" Storyboard.TargetProperty="Opacity" To="1" Duration="0" />-->
                                            <DoubleAnimation Storyboard.TargetName="ContentElement" Storyboard.TargetProperty="Opacity" To="1" Duration="0" />
                                            <DoubleAnimation Storyboard.TargetName="Watermark" Storyboard.TargetProperty="Opacity" To="0" Duration="0" />
                                            <!--<DoubleAnimation Storyboard.TargetName="FocusVisualElement" Storyboard.TargetProperty="Opacity" To="1" Duration="0" />-->
                                        </Storyboard>
                                    </vsm:VisualState>
                                </vsm:VisualStateGroup>
                            </vsm:VisualStateManager.VisualStateGroups>
                            <Border x:Name="Border" BorderThickness="{TemplateBinding BorderThickness}" CornerRadius="1" Opacity="1" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}">
                                <Grid>
                                    <Border x:Name="ReadOnlyVisualElement" Background="#72F7F7F7" Opacity="0" />
                                    <Border x:Name="MouseOverBorder" BorderThickness="0" BorderBrush="Transparent">
                                        <ScrollViewer x:Name="ContentElement" Padding="{TemplateBinding Padding}" BorderThickness="0" IsTabStop="False" Margin="0,-1.5,0,0" />
                                    </Border>
                                    <ContentControl
                                      x:Name="Watermark"
                                      Opacity="0"
                                      IsTabStop="False"
                                      IsHitTestVisible="False"
                                      Content="{TemplateBinding Watermark}"
                                      Foreground="{StaticResource WatermarkBrush}"
                                      Background="{TemplateBinding Background}"
                                      FontFamily="{TemplateBinding FontFamily}"
                                      FontSize="{TemplateBinding FontSize}"
                                      FontStretch="{TemplateBinding FontStretch}"
                                      FontStyle="{TemplateBinding FontStyle}"
                                      FontWeight="{TemplateBinding FontWeight}"
                                      Padding="{TemplateBinding Padding}"
                                      VerticalContentAlignment="Center"
                                      Margin="0,-1.5,0,0"/>
                                </Grid>
                            </Border>
                            <Border x:Name="DisabledVisualElement" Background="#A5F7F7F7" BorderBrush="#A5F7F7F7" BorderThickness="{TemplateBinding BorderThickness}" Opacity="0" IsHitTestVisible="False"/>
                            <!--<Border x:Name="FocusVisualElement" BorderBrush="#FF6DBDD1" BorderThickness="{TemplateBinding BorderThickness}" Margin="1" Opacity="0" IsHitTestVisible="False"/>-->
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>
    
    <Grid x:Name="LayoutRoot">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>

        <Grid x:Name="SearchControl" Grid.Column="0" Margin="0,0,0,0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Rectangle Grid.ColumnSpan="3" Fill="#FFFFFFFF" RadiusX="15" RadiusY="15" StrokeThickness="1">
                <Rectangle.Stroke>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="#FF4F4F4F"/>
                        <GradientStop Color="#FF464646" Offset="1"/>
                    </LinearGradientBrush>
                </Rectangle.Stroke>
            </Rectangle>
            <berico:SplitButton x:Name="SearchButton" Command="{Binding ButtonClickCommand}" Cursor="Hand" Height="Auto" Width="Auto" Margin="1,1,0,1" Style="{StaticResource SearchButtonStyle}" HorizontalContentAlignment="Left" VerticalContentAlignment="Center">
                <berico:SplitButton.Content>
                    <Image Source="{Binding CaptionImage}" Height="20" Width="20" />
                </berico:SplitButton.Content>
                <berico:SplitButton.Background>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="#FFFFFFFF"/>
                        <GradientStop Color="#FFFFFFFF" Offset="1"/>
                        <GradientStop Color="#FFE0E0E0" Offset="0.49"/>
                        <GradientStop Color="#FFE0E0E1" Offset="0.50"/>
                    </LinearGradientBrush>
                </berico:SplitButton.Background>
                <berico:SplitButton.DropDownContent>
                    <ListBox x:Name="MenuListBox" Style="{StaticResource MenuListStyle}" SelectionMode="Single" SelectedItem="{Binding SelectedItem}" ItemsSource="{Binding MenuItems}">
                        <i:Interaction.Triggers>
                            <i:EventTrigger EventName="SelectionChanged">
                                <cmd:EventToCommand Command="{Binding SelectionChangedCommand}"  PassEventArgsToCommand="True"/>
                            </i:EventTrigger>
                        </i:Interaction.Triggers>
                    </ListBox>
                </berico:SplitButton.DropDownContent>
            </berico:SplitButton>
            <MS:WatermarkedTextBox x:Name="SearchTextBox" Text="{Binding SearchText, Mode=TwoWay}" Height="Auto" VerticalAlignment="Stretch" Grid.Column="1" Style="{StaticResource LowKeyWatermarkedTextboxStyle}" Margin="1,2,18,2" Watermark="Search graph..." VerticalContentAlignment="Center" Cursor="IBeam" BorderThickness="0" AcceptsReturn="False" FontSize="9">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="KeyDown">
                        <cmd:EventToCommand Command="{Binding KeyDownCommand}"  PassEventArgsToCommand="True"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </MS:WatermarkedTextBox>
            <Button x:Name="ClearButton" Grid.Column="3" Height="15" Width="15" Margin="0,0,8,0" Visibility="Collapsed" Style="{StaticResource PlainRoundButtonStyle}">
                <Button.Content>
                    <TextBlock Text="X" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="10" Foreground="#FFFFFFFF" FontWeight="Bold" />
                </Button.Content>
            </Button>
        </Grid>
        
        <!-- Advanced Options Toggle -->
        <ToggleButton x:Name="SearchOptionsButton" Grid.Column="1" Margin="4,-1,4,0" Width="20" Style="{StaticResource CollapseButtonStyle}" RenderTransformOrigin="0.5,0.5" Visibility="{Binding IsAdvancedSearchVisible, Converter={StaticResource VisibilityConverter}}" >
            <ToggleButton.RenderTransform>
                <TransformGroup>
                    <ScaleTransform/>
                    <SkewTransform/>
                    <RotateTransform/>
                    <TranslateTransform/>
                </TransformGroup>
            </ToggleButton.RenderTransform>
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="Checked">
                    <cmd:EventToCommand Command="{Binding AdvancedOptionsButtonCheckedCommand}" PassEventArgsToCommand="False"/>
                </i:EventTrigger>
                <i:EventTrigger EventName="Unchecked">
                    <cmd:EventToCommand Command="{Binding AdvancedOptionsButtonUncheckedCommand}" PassEventArgsToCommand="False"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>            
        </ToggleButton>

        <!-- The Advanced Search and Options popup -->
        <Popup x:Name="SearchOptionsPopup" HorizontalOffset="0" VerticalOffset="0">
            <Grid x:Name="SearchOptionsPanel" Height="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Top" Opacity="1">
                <Grid.Resources>
                </Grid.Resources>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Border Grid.Column="0" Grid.Row="0" HorizontalAlignment="Right" Width="2" BorderThickness="1" Height="8" Background="#FFB9BABF">
                    <Border.BorderBrush>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FF4F4F4F"/>
                            <GradientStop Color="#FF464646" Offset="1"/>
                        </LinearGradientBrush>
                    </Border.BorderBrush>
                </Border>
                <!-- Small portion that connects to button -->
                <Border Grid.Column="1" Grid.Row="0" VerticalAlignment="Top" Width="19" BorderThickness="0,0,2,0" Height="8" Background="#FFB9BABF">
                    <Border.BorderBrush>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FF4F4F4F"/>
                            <GradientStop Color="#FF464646" Offset="1"/>
                        </LinearGradientBrush>
                    </Border.BorderBrush>
                </Border>
                <!-- Main Header Area -->
                <Border Grid.Column="0" Grid.Row="1" CornerRadius="8,0,0,0" BorderThickness="2,2,0,2" Height="25" Margin="0,0,0,0" Background="#FFB9BABF">
                    <Border.BorderBrush>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FF4F4F4F"/>
                            <GradientStop Color="#FF464646" Offset="1"/>
                        </LinearGradientBrush>
                    </Border.BorderBrush>
                    <TextBlock x:Name="HeaderText" Padding="10,0,0,0" Text="Advanced Search Options" VerticalAlignment="Center" FontSize="13.333" Foreground="Black" />
                </Border>
                <!-- Header Area Extension -->
                <Border Grid.Column="1" Grid.Row="1" Width="19" Height="25" BorderThickness="0,0,2,2" Background="#FFB9BABF">
                    <Border.BorderBrush>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FF4F4F4F"/>
                            <GradientStop Color="#FF464646" Offset="1"/>
                        </LinearGradientBrush>
                    </Border.BorderBrush>
                </Border>
                <!-- Main Display Area Shadow -->
                <Border Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="2" Height="300" CornerRadius="0" Margin="7,0,-5,-7" Opacity=".4" Background="#FF000000" />
                <!-- Main Display Area -->
                <Border Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="2" Background="White" BorderThickness="2,0,2,2" Height="300" CornerRadius="0">
                    <Border.BorderBrush>
                        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            <GradientStop Color="#FF4F4F4F"/>
                            <GradientStop Color="#FF464646" Offset="1"/>
                        </LinearGradientBrush>
                    </Border.BorderBrush>
                    <!-- The actual advanced search component goes here -->
                    <local:AdvancedSearch x:Name="AdvancedSearchControl" />
                </Border>
            </Grid>
        </Popup>

    </Grid>
    
</UserControl>
